/**
 * 
 */
package org.lrq.voidwalker.capricornus.crawler.qqTech;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.geccocrawler.gecco.annotation.Gecco;
import com.geccocrawler.gecco.annotation.HtmlField;
import com.geccocrawler.gecco.annotation.JSVar;
import com.geccocrawler.gecco.annotation.Request;
import com.geccocrawler.gecco.annotation.RequestParameter;
import com.geccocrawler.gecco.annotation.Text;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.spider.HtmlBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author macbook
 *
 */
@Gecco(matchUrl="http://tech.qq.com/a/{date}/{articleId}.htm", pipelines={"QQTechArticlePipeLine"})
public class QQTechArticle implements HtmlBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5349730001661409240L;

	@Request
	private HttpRequest request;

	@RequestParameter
	private String articleId;
	
	@RequestParameter
	private String date;
	@Text
	@HtmlField(cssPath=".qq_article .hd h1")
	private String title;
	
	@Text
	@HtmlField(cssPath=".qq_article .bd .Cnt-Main-Article-QQ .text")
	private List<String> content;



	/*@Text(own=false)
	@HtmlField(cssPath="body")
	private String body;*/



	@JSVar(var="ARTICLE_INFO",jsonpath="tags")
	private List<String> tags;

	@Text
	@HtmlField(cssPath=".a_Info .a_catalog a")
	private String catelog;

	@Text
	@HtmlField(cssPath=".a_Info .a_time")
	private String publishTime;

	/*@JSVar(var="ARTICLE_INFO",jsonpath="id")
	private String id;*/

	/*public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}*/

	public String getArticleId() {
		return articleId;
	}

	public void setArticleId(String articleId) {
		this.articleId = articleId;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}


	public List<String> getContent() {
		return content;
	}

	public void setContent(List<String> content) {
		this.content = content;
	}


	public HttpRequest getRequest() {
		return request;
	}

	public void setRequest(HttpRequest request) {
		this.request = request;
	}

	public List<String> getTags() {
		return tags;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}



	public Map<String,Object> getMapBean(){
		Map<String,Object> map = new HashMap<String,Object>();

		map.put("articleId",date+articleId);

		map.put("url",request.getUrl());

		map.put("date",date);

		map.put("tags",tags);

		map.put("title",title);

		map.put("catelog",catelog);

		map.put("publishTime",publishTime);

		String content = "";
		for(String str:this.content){
			content+=str;
		}
		map.put("content",content);
		return map;
	}
}
